package com.yimils.core.goods.controller;

import com.yimils.core.common.dto.RspBase;
import com.yimils.core.goods.dto.GoodsAddReq;
import com.yimils.core.goods.dto.GoodsQueryReq;
import com.yimils.core.goods.dto.GoodsUpdateReq;
import com.yimils.core.goods.serivce.GoodsService;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

@RestController
@Validated
public class GoodsController {
    @Resource(name = "goodsService")
    GoodsService goodsService;

    @PostMapping("/goods/save")
    public RspBase saveGoods(@RequestBody GoodsAddReq goodsAddReq) {
        if (goodsService.saveGoods(goodsAddReq)) {
            return RspBase.OK("成功");
        }
        return RspBase.OK("失败");
    }


    @PutMapping("/goods/update")
    public RspBase updateGoods(@RequestBody GoodsUpdateReq goodsUpdateReq) {
        if (goodsService.updateGoods(goodsUpdateReq)) {
            return RspBase.OK("成功");
        }
        return RspBase.OK("失败");
    }

    @DeleteMapping("/goods/delete")
    public RspBase deleteGoods(List<Long> goodsIds) {
        if (goodsService.deleteGoods(goodsIds)) {
            return RspBase.OK("成功");
        }
        return RspBase.OK("失败");
    }

    @GetMapping("/goods/list")
    public RspBase listGoods(@RequestBody GoodsQueryReq goodsQueryReq) {
        RspBase rsp = RspBase.OK();
        rsp.put("data", goodsService.listGoods(goodsQueryReq));
        return rsp;
    }

    @PutMapping("/goods/audit")
    public RspBase audit(Long goodsId, String auditState) {
        if (goodsService.audit(goodsId, auditState)) {
            return RspBase.OK("成功");
        }
        return RspBase.OK("失败");
    }

    @PutMapping("/goods/putaway")
    public RspBase putaway(Long goodsId, String putawayState) {
        if (goodsService.putaway(goodsId, putawayState)) {
            return RspBase.OK("成功");
        }
        return RspBase.OK("失败");
    }
}
